<?php

namespace App\Admin\Controllers;

use App\Admin\Extensions\Tools\UserGender;
use App\Models\Movie;
use App\User;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;
use Encore\Admin\Tree;
use Encore\Admin\Layout\Row;
use \Illuminate\Http\Request;
use Encore\Admin\Layout\Content;

class SaleAccounts extends AdminController
{
    /**
     * Title for current resource.
     *
     * @var string
     */
    protected $title = 'sale-accounts';


    public function index(Content $content): Content
    {
        return $content
            ->title('销售账号')
            ->description(trans('admin.list'))
            ->row(function (Row $row) {
                $row->column(6, '123');
//
//                $row->column(6, function (Column $column) {
//                    $form = new \Encore\Admin\Widgets\Form();
//                    $form->action(admin_url('sale-accounts'));
//
//                    $menuModel = new SaleAccount();
//
//                    $form->select('parent_id', trans('admin.parent_id'))->options($menuModel::selectOptions());
//                    $form->text('title', trans('admin.title'))->rules('required');
//                    $form->select('type', trans('类型'))
//                        ->options($menuModel::ChoseType)
//                        ->rules('required')
//                        ->help('所选择的类型需属于父级菜单的下级,（列如，父级菜单为 平台，类型需要选择为 国家）');
//                    $form->hidden('_token')->default(csrf_token());
//                    $column->append((new Box(trans('新增菜单'), $form))->style('success'));
//                });
            });
    }

    /**
     * @return \Encore\Admin\Tree
     */
    protected function treeView(): Tree
    {
        $menuModel = new SaleAccount();

        $tree = new Tree(new $menuModel());

        $tree->disableCreate();
        $tree->disableSave();
        $type = $menuModel::Type;
        $tree->branch(function ($branch) use ($type){
            $payload = "&nbsp;<strong>{$branch['title']}</strong>&nbsp;-&nbsp;{$type[$branch['type']]}";


            return $payload;
        });

        return $tree;
    }

}
